package com.example.myworkers.controller;

import com.example.myworkers.model.Car;
import com.example.myworkers.model.Goods;
import com.example.myworkers.model.Grant;
import com.example.myworkers.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 编写者：门硕然
 */

@Api(tags = "Goods")
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @ApiOperation(value = "添加方法")
    @GetMapping("/addGoods")
    @CrossOrigin
    public int addGoods( Goods goods){
        System.out.println("进入添加信息接口");
        return goodsService.insertGoods(goods);
    }

    @ApiOperation(value = "查询方法-单个")
    @GetMapping("/getOne")
    @CrossOrigin
    public Goods getGoods(int id){
        System.out.println("进入单条查询接口");
        Goods goods=goodsService.selectGoods(id);
        System.out.println("返回的数据集合为"+goods.getName());
        return goods;
    }



    @ApiOperation(value = "修改方法")
    @GetMapping("/editGoods")
    @CrossOrigin
    public int editGoods(Goods goods){
        System.out.println("进入修改接口");
        return goodsService.updateGoods(goods);
    }


    @ApiOperation(value = "删除方法")
    @GetMapping("/deleteGoods")
    @CrossOrigin
    public int deleteGoods(int id){
        System.out.println("进入删除接口");
        int returnValue=0;
        if (id!=0){
            returnValue=goodsService.deleteGoods(id);
        }
        return returnValue;
    }




}
